/**
 * 
 */
package com.alstudio.core.voip;

import com.alstudio.event.ALEventDeliver;

/**
 * @author alonso lee
 * 
 */
public class ALVoipCallUIEventDispatcher {

	public static void postVoipCallEvent(ALVoipUIEvent event) {
		ALEventDeliver.getDefaultAlEventDeliver().postALEvent(event);
	}

	public static void postVoipCallEvent(ALVoipUIEventType type) {
		ALVoipUIEvent event = new ALVoipUIEvent();
		event.setType(type);
		ALEventDeliver.getDefaultAlEventDeliver().postALEvent(event);
	}
	
	public static void postVoipCallEvent(ALVoipUIEventType type,String callId) {
		ALVoipUIEvent event = new ALVoipUIEvent();
		event.setType(type);
		event.setData(callId);
		ALEventDeliver.getDefaultAlEventDeliver().postALEvent(event);
	}
	
	
	public static void postVoipCallEvent(CallState curState, CallState lastState) {
		ALVoipUIEvent event = new ALVoipUIEvent();
		event.setType(getALVoipUIEventTypeByCallState(curState, lastState));
		ALEventDeliver.getDefaultAlEventDeliver().postALEvent(event);
	}

	public static void postVoipCallEvent(CallState curState,
			CallState lastState, Object callInfo) {
		ALVoipUIEvent event = new ALVoipUIEvent();
		event.setType(getALVoipUIEventTypeByCallState(curState, lastState));
		event.setData(callInfo);
		ALEventDeliver.getDefaultAlEventDeliver().postALEvent(event);
	}

	private static ALVoipUIEventType getALVoipUIEventTypeByCallState(
			CallState curState, CallState lastState) {
		ALVoipUIEventType type = ALVoipUIEventType.ALVOIP_UI_EVENT_NONE;
		

		switch (curState) {
		case CALL_ESTABLISED:
			type = ALVoipUIEventType.ALVOIP_UI_EVENT_ESTABLISHED_CALL;
			break;
		case CALL_HANDUP:
			type = ALVoipUIEventType.ALVOIP_UI_EVENT_HANDUP_CALL;
			break;
		case CALL_INCOMMING:
			type = ALVoipUIEventType.ALVOIP_UI_EVENT_INCOMMING_CALL;
			break;
		case CALL_INCOMMING_NOTICE:
			type = ALVoipUIEventType.ALVOIP_UI_EVENT_INCOMMING_CALL_NOTICE;
			break;
		case CALL_OUTGOING:
			type = ALVoipUIEventType.ALVOIP_UI_EVENT_OUTGOING_CALL;
			break;
		case CALL_REJECT:
			type = ALVoipUIEventType.ALVOIP_UI_EVENT_REJECT_CALL;
			break;
		default:
			break;

		}

		return type;
	}
}
